package com.cpd.blog.manager.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cpd.blog.common.constant.StatusCode;
import com.cpd.blog.common.utils.LogUtil;
import com.cpd.blog.entity.Comment;
import com.cpd.blog.manager.manager.CommentsManager;
import com.cpd.blog.manager.mapper.CommentsMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @Author: Copydown
 * @Date: 2022/04/30/21:02
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class CommentsManagerImpl implements CommentsManager {

    private final CommentsMapper commentsMapper;

    @Override
    public boolean deleteCommentsByArticleId(Long articleId) {
        QueryWrapper<Comment> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(Comment::getArticleId, articleId);
        if (commentsMapper.delete(queryWrapper) >= 0) {
            LogUtil.log(StatusCode.COMMENT_DELETE_SUCCESS);
            return true;
        }
        return false;
    }
}
